<?
	$attributes = array('class' => 'email', 'id' => 'checknew');
	echo form_open('', $attributes);
?>
<table class="admindata" id="admindata">
    <thead>
        <tr>
            <th colspan="3"> <input type="button" onclick="closes()" name="btn_submit" class="submit" value="Chọn">
                <?=lang('total');?> <?=$num?> <?=lang('record');?>
                <span class="pages"><?=$pagination?></span> </th>
        </tr>
        <tr>
            <th class="checkbox"><input type="checkbox" name="sa" id="sa" onclick="check_all();" /></th>
            <th><?=lang('title');?></th>
            <th>Create Date</th>
        </tr>
    </thead>
    <?
        $k=1;
        $i=1;
        foreach($list as $rs):
	?>
        <tr class="row<?=$k?>">
            <td><input type="checkbox" name="ar_id[]" value="<?=$rs->news_id?>" class="checkbox_id-<?=$i?>" /></td>
            <td><?=$rs->lb_title?></td>
            <td><?=format_date_show($rs->dt_create)?></td>
        </tr>
    <?
        $k=1-$k;
        $i++;
        endforeach;
	?>
    <tfoot>
    <td colspan="3"><input type="button" onclick="closes()" name="btn_submit" class="submit" value="Chọn">
            <?=lang('total');?> <?=$num?> <?=lang('record');?>
            <span class="pages"><?=$pagination?></span></td>
            </tfoot>
</table>
<?=form_close()?>
<script type="text/javascript">
	/*function insert(id, name)
	{
		$("#id_relate", top.document).val(id);
		$("#news_relate", top.document).val(name);
		parent.$.fn.colorbox.close();
	}*/
	function closes()
	{
		var leng_row=document.getElementById('admindata').rows.length-3;
		var arr_id= new Array();
		for(var i=1;i<=leng_row;i++)
		{
			var value 	= 	$(".checkbox_id-"+i).val();
			var checked = 	$(".checkbox_id-"+i).is(':checked'); 
			
			if(value >0 && checked){
			  arr_id.push(value);
			}
		}
		
		if(arr_id.length>0)
		{
			var url = '<?=base_url();?>news/get_news_title_from_listid';
			$.post(url,{arr_id:arr_id},function(result){
				parent.$("#tblnews").last().append(result);
				parent.$.fn.colorbox.close();
				//parent.$("#id_relate").val(parent.$("#id_relate").val() +','+a) ;
			 });
		}else{
			parent.$.fn.colorbox.close();
		}
		//parent.$.fn.colorbox.close();
	}
	
	function check_all()
	{
		var leng_row=document.getElementById('admindata').rows.length-3;
		var checked = $("#sa").is(':checked'); 
		if(checked){
			 for(var i=1;i<=leng_row;i++)
			 {
				$(".checkbox_id"+i).attr('checked',true); 
			 }
		}else{
			 for(var i=1;i<=leng_row;i++)
			 {
				$(".checkbox_id"+i).attr('checked',''); 
			 }
		}
	}
</script>